import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import './index.css'
import App from './App.tsx'

// 增强的iOS Safari URL栏自动隐藏功能
const hideUrlBar = () => {
  // 检测是否为移动设备
  const isMobile = /iPhone|iPad|iPod|Android|Mobile/i.test(navigator.userAgent);

  if (isMobile) {
    const forceHide = () => {
      // 多重方法强制隐藏URL栏
      const methods = [
        () => window.scrollTo(0, 1),
        () => window.scrollTo(0, 10),
        () => window.scrollTo(0, -1),
        () => window.scrollBy(0, -window.pageYOffset),
        () => {
          document.documentElement.scrollTop = 1;
          document.body.scrollTop = 1;
        },
        () => {
          window.requestAnimationFrame(() => {
            window.scrollTo(0, 1);
          });
        }
      ];

      methods.forEach((method, index) => {
        setTimeout(method, index * 50);
      });
    };

    // 页面加载后立即执行
    setTimeout(forceHide, 100);

    // 监听各种事件隐藏URL栏
    const events = ['load', 'resize', 'orientationchange', 'touchstart', 'touchend', 'click'];

    events.forEach(event => {
      window.addEventListener(event, forceHide, { passive: true });
    });

    // 定期检查并隐藏URL栏
    setInterval(() => {
      if (window.pageYOffset === 0) {
        forceHide();
      }
    }, 3000);
  }
};

// 页面加载完成后执行
if (document.readyState === 'loading') {
  document.addEventListener('DOMContentLoaded', hideUrlBar);
} else {
  hideUrlBar();
}

createRoot(document.getElementById('root')!).render(
  <StrictMode>
    <App />
  </StrictMode>,
)
